//
//  ByJobCell.m
//  jmsfhz_ios
//
//  Created by pro on 16/7/19.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByJobCell.h"

@implementation ByJobCell

+ (instancetype)createCellInTableview:(UITableView *)table {
    
    static NSString *cellIdentifier = @"ByJobCell";
    ByJobCell *cell = [table dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initSubviews];
    }
    return self;
}

- (void)initSubviews {
    
    CGFloat x, y, width, height;
    /** 公司图片 */
    self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
    self.iconView.image = [UIImage imageNamed:@"defaultImage"];
    [self.contentView addSubview:self.iconView];
    
    /** 认证图片 */
    width = 45.0;
    height = width / 3;
    x = SCREEN_WIDTH - 10 - width;
    y = self.iconView.top + 5;
    self.authenticationView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.authenticationView.image = [UIImage imageNamed:@"就业-认证"];
    [self.contentView addSubview:self.authenticationView];
    
    /** 公司Label */
    x = self.iconView.right + 10;
    y = self.iconView.top + 5;
    width = self.authenticationView.left - 10 - x;
    height = 15;
    self.companyLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.companyLabel.textColor = [UIColor blackColor];
    self.companyLabel.font = FONT(14);
    self.companyLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.companyLabel];
    self.companyLabel.text = @"杭州博也网络科技有限公司";
    
    /** 地址Label 和 地址图片 */
    x = self.companyLabel.left;
    y = self.companyLabel.bottom + 10;
    width = 12;
    height = 12;
    UIImageView *addressImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    addressImageView.image = [UIImage imageNamed:@"就业-地址"];
    [self.contentView addSubview:addressImageView];
    
    x = addressImageView.right + 5;
    y = addressImageView.top;
    width = 0;
    height = 15;
    self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.addressLabel.textColor = [UIColor lightGrayColor];
    self.addressLabel.font = FONT(12);
    self.addressLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.addressLabel];
    self.addressLabel.text = @"下沙江干区";
    
    self.addressLabel.width = [self.addressLabel.text getSizeOfString:12].width;
    addressImageView.center = CGPointMake(addressImageView.center.x, self.addressLabel.center.y);
    
    /** 时间Label 和 时间图片 */
    x = self.addressLabel.right + 20;
    y = addressImageView.top;
    width = 12;
    height = 12;
    UIImageView *dateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    dateImageView.tag = 100;
    dateImageView.image = [UIImage imageNamed:@"就业-时间"];
    [self.contentView addSubview:dateImageView];
    
    x = dateImageView.right + 5;
    y = self.addressLabel.top;
    width = 0;
    height = 15;
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.dateLabel.textColor = [UIColor lightGrayColor];
    self.dateLabel.font = FONT(12);
    self.dateLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.text = @"2016-7-7";
    
    self.dateLabel.width = [self.dateLabel.text getSizeOfString:12].width;
}

- (void)setModel:(ByNetJobItemModel *)model {
    _model = model;
    [self.iconView setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:[UIImage imageNamed:@"defaultImage"]];
    self.companyLabel.text = model.title;
    self.authenticationView.hidden = ![model.is_auth_e boolValue];   // 已认证则不隐藏，否则隐藏
    self.addressLabel.text = model.address;
    self.addressLabel.width = [self.addressLabel.text getSizeOfString:12].width;
    UIImageView *dateImageView = [self.contentView viewWithTag:100];
    dateImageView.left = self.addressLabel.right + 10;
    self.dateLabel.text = model.update_time;
    self.dateLabel.left = dateImageView.right + 5;
    self.dateLabel.width = SCREEN_WIDTH - 10 - self.dateLabel.left;
}
- (void)setMyHandModel:(ByNetJobItemModel *)myHandModel {
    _myHandModel = myHandModel;
    [self.iconView setImageWithURL:[NSURL URLWithString:_myHandModel.employ_logo] placeholderImage:[UIImage imageNamed:@"defaultImage"]];
    self.companyLabel.text = _myHandModel.employ_title;
//    self.authenticationView.hidden = ![_myHandModel.is_auth_e boolValue];   // 已认证则不隐藏，否则隐藏
    self.addressLabel.text = _myHandModel.employ_address;
    self.addressLabel.width = [self.addressLabel.text getSizeOfString:12].width;
    UIImageView *dateImageView = [self.contentView viewWithTag:100];
    dateImageView.left = self.addressLabel.right + 10;
    self.dateLabel.text = _myHandModel.create_time;
    self.dateLabel.left = dateImageView.right + 5;
    self.dateLabel.width = SCREEN_WIDTH - 10 - self.dateLabel.left;

}


@end
